package org.mat.ipaas.ucenter.bff.admin.modules.system;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.mat.framework.lang.dto.MatApiResponse;
import org.mat.ipaas.ucenter.service.api.system.SysAnnouncementSendRestAPI;
import org.mat.ipaas.ucenter.service.dto.system.entity.SysAnnouncementSendDTO;
import org.mat.ipaas.ucenter.service.dto.system.model.AnnouncementSendModelDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

 /**
 * @Title: Controller
 * 用户通告阅读标记表
 */
@RestController
@RequestMapping("/sys/sysAnnouncementSend")
@Slf4j
public class SysAnnouncementSendController {

	@Autowired
	private SysAnnouncementSendRestAPI sysAnnouncementSendRestAPI;

	/**
	  * 分页列表查询
	 * @param sysAnnouncementSendDTO
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@GetMapping(value = "/list")
	public MatApiResponse<IPage<SysAnnouncementSendDTO>> queryPageList(SysAnnouncementSendDTO sysAnnouncementSendDTO,
																	   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
																	   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
																	   HttpServletRequest req) {
		MatApiResponse<IPage<SysAnnouncementSendDTO>> matApiResponse = sysAnnouncementSendRestAPI.queryPageList(sysAnnouncementSendDTO, pageNo, pageSize, req);
		return matApiResponse;
	}
	
	/**
	  *   添加
	 * @param sysAnnouncementSendDTO
	 * @return
	 */
	@PostMapping(value = "/add")
	public MatApiResponse<SysAnnouncementSendDTO> add(@RequestBody SysAnnouncementSendDTO sysAnnouncementSendDTO) {
		MatApiResponse<SysAnnouncementSendDTO> matApiResponse = sysAnnouncementSendRestAPI.add(sysAnnouncementSendDTO);
		return matApiResponse;
	}
	
	/**
	  *  编辑
	 * @param sysAnnouncementSendDTO
	 * @return
	 */
	@PutMapping(value = "/edit")
	public MatApiResponse<SysAnnouncementSendDTO> eidt(@RequestBody SysAnnouncementSendDTO sysAnnouncementSendDTO) {
		MatApiResponse<SysAnnouncementSendDTO> matApiResponse = sysAnnouncementSendRestAPI.eidt(sysAnnouncementSendDTO);
		return matApiResponse;
	}
	
	/**
	  *   通过id删除
	 * @param id
	 * @return
	 */
	@DeleteMapping(value = "/delete")
	public MatApiResponse<SysAnnouncementSendDTO> delete(@RequestParam(name="id",required=true) String id) {
		MatApiResponse<SysAnnouncementSendDTO> matApiResponse = sysAnnouncementSendRestAPI.delete(id);
		return matApiResponse;
	}
	
	/**
	  *  批量删除
	 * @param ids
	 * @return
	 */
	@DeleteMapping(value = "/deleteBatch")
	public MatApiResponse<SysAnnouncementSendDTO> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		MatApiResponse<SysAnnouncementSendDTO> matApiResponse = sysAnnouncementSendRestAPI.deleteBatch(ids);
		return matApiResponse;
	}
	
	/**
	  * 通过id查询
	 * @param id
	 * @return
	 */
	@GetMapping(value = "/queryById")
	public MatApiResponse<SysAnnouncementSendDTO> queryById(@RequestParam(name="id",required=true) String id) {
		MatApiResponse<SysAnnouncementSendDTO> matApiResponse = sysAnnouncementSendRestAPI.queryById(id);
		return matApiResponse;
	}
	
	/**
	 * @功能：更新用户系统消息阅读状态
	 * @param json
	 * @return
	 */
	@PutMapping(value = "/editByAnntIdAndUserId")
	public MatApiResponse<SysAnnouncementSendDTO> editById(@RequestBody JSONObject json) {
		MatApiResponse<SysAnnouncementSendDTO> matApiResponse = sysAnnouncementSendRestAPI.editById(json);
		return matApiResponse;
	}
	
	/**
	 * @功能：获取我的消息
	 * @return
	 */
	@GetMapping(value = "/getMyAnnouncementSend")
	public MatApiResponse<Page<AnnouncementSendModelDTO>> getMyAnnouncementSend(AnnouncementSendModelDTO announcementSendModelDTO,
																				@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
																				@RequestParam(name="pageSize", defaultValue="10") Integer pageSize) {
		MatApiResponse<Page<AnnouncementSendModelDTO>> matApiResponse = sysAnnouncementSendRestAPI.getMyAnnouncementSend(announcementSendModelDTO, pageNo, pageSize);
		return matApiResponse;
	}

	/**
	 * @功能：一键已读
	 * @return
	 */
	@PutMapping(value = "/readAll")
	public MatApiResponse<SysAnnouncementSendDTO> readAll() {
		MatApiResponse<SysAnnouncementSendDTO> matApiResponse = sysAnnouncementSendRestAPI.readAll();
		return matApiResponse;
	}


	 /**
	  * 根据消息发送记录ID获取消息内容
	  * @param sendId
	  * @return
	  */
	 @GetMapping(value = "/getOne")
	 public MatApiResponse<AnnouncementSendModelDTO> getOne(@RequestParam(name="sendId",required=true) String sendId) {
		 MatApiResponse<AnnouncementSendModelDTO> matApiResponse = sysAnnouncementSendRestAPI.getOne(sendId);
		 return matApiResponse;
	 }
}
